package com.example.vehicle.controller;

import com.example.entity.Household;
import com.example.result.CommonResult;
import com.example.utils.MyPageHelper;
import com.example.utils.PageRequest;
import com.example.vehicle.service.VehicleService;
import com.example.vehicle.vo.VehicleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/vehicle")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;
    /**
     * 停车场管理-车辆全查
     */
    @GetMapping("/getVehicle")
    public CommonResult getVehicle(@RequestParam String vehicleCode, PageRequest pageRequest){
        MyPageHelper.StartPage(pageRequest);
        CommonResult commonResult = vehicleService.getVehicle(vehicleCode);
        return commonResult;
    }
    /**
     * 停车场管理-车辆删除
     */
    @DeleteMapping("/delVehicle")
    public CommonResult delVehicle(Integer id){
        int i = vehicleService.delVehicle(id);
        return CommonResult.ok(i);
    }
    /**
     * 车辆管理-车辆增改
     */
    @PostMapping("/saveOrUpdateVehicle")
    public CommonResult saveOrUpdateVehicle(MultipartFile file, VehicleVO vehicle) throws IOException {
        int i = vehicleService.saveOrUpdateVehicle(file,vehicle);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.fail();
        }
    }
    /**
     * 车辆管理-用户全查
     */
    @GetMapping("/getHouseAll")
    public List<Household> getHouseAll(@RequestParam String householdType){
        return vehicleService.getHouseAll(householdType);
    }
}
